l=['zero','one','two','three','four','five','six','seven','eight','nine']
try:

    a, b, c = map(str, input().split(" "))
    a=str(l.index(a))
    b=str(l.index(b))
    c=str(l.index(c))
    s=[a,b,c]
    s=int(''.join(s))
    if a!='0':
        def prime(n):
            k = 2
            while k ** 2 <= n:
                if n / k != 1 and n % k == 0:
                    return False
                k += 1
            if k ** 2 > n:
                return True
        l1 = []
        l2 = []
        k=1
        if prime(s)==True:
            print(s)
        else:
            for i in range(s-100*k,s):
                if prime(i)==True and i>100:
                    l1.append(i)
            for i in range(s,s+100*k+1):
                if prime(i)==True and i>100 and i<1000:
                    l2.append(i)
        min=0
        max=0
        while min==0 or max==0:
            try:
                max=l2[0]
                min=l1[-1]
                if s-max>s-min:
                    print(min)
                    break
                elif s-max<s-min:
                    print(max)
                    break
                else:
                    print(min)
                    break
            except:
                for i in range(s-100*k,s):
                    if prime(i)==True and i>100:
                        l1.append(i)
                for i in range(s,s+100*k+1):
                    if prime(i)==True and i>100 and i<1000:
                        l2.append(i)
    else:
        print("Wrong input")
except:
    print("Wrong input")
